package com.wwwarehouse.contract.contract;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.bean.response.CardDeskTaskResponseBean;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.popupwindow.EasyPopupWindow;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.eventbus_event.BackListenerEvent;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.DialogTools;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.common.tools.PopUpUtils;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.common.tools.rsa.StringUtils;
import com.wwwarehouse.contract.bean.CheckPermission;
import com.wwwarehouse.contract.bean.ContinueReleaseCardBean;
import com.wwwarehouse.contract.bean.ObligationItemEvent;
import com.wwwarehouse.contract.bean.RefreshEvent;
import com.wwwarehouse.contract.bean.ReleaseObjectBean;
import com.wwwarehouse.contract.bean.ReleaseSupplyGoodsListBean;
import com.wwwarehouse.contract.bean.ResourceItemBean;
import com.wwwarehouse.contract.bean.RleaseInfoAndFunctionBean;
import com.wwwarehouse.contract.bean.SettingRuleBean;
import com.wwwarehouse.contract.bean.SupplyDialogBean;
import com.wwwarehouse.contract.common.ContractCommon;
import com.wwwarehouse.contract.contract.info.InfoCardCompulsoryFragment;
import com.wwwarehouse.contract.contract.info.InfoCardDeliverItemFragment;
import com.wwwarehouse.contract.contract.info.InfoCardOrderDetailViewPagerFragment;
import com.wwwarehouse.contract.contract.info.InfoCardPayItemFragment;
import com.wwwarehouse.contract.contract.modify.IssuedGoodsViewPagerFragment;
import com.wwwarehouse.contract.contract.publishgoods.PublishGoodSFragment;
import com.wwwarehouse.contract.core.ContractConstant;
import com.wwwarehouse.contract.event.CountEvent;
import com.wwwarehouse.contract.event.DeliveryItemEvent;
import com.wwwarehouse.contract.event.EffectTimeEvent;
import com.wwwarehouse.contract.event.NotifyDeleteEvent;
import com.wwwarehouse.contract.event.PayItemEvent;
import com.wwwarehouse.contract.event.PublishEvent;
import com.wwwarehouse.contract.event.PublishingRulesEvent;
import com.wwwarehouse.contract.event.RefreshPublishGoodsEvent;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;
import de.greenrobot.event.EventBus;

import static com.alibaba.fastjson.JSON.parseArray;
import static com.alibaba.fastjson.JSON.parseObject;
import static contract.wwwarehouse.com.contract.R.string.delivery_time_title_card;
import static contract.wwwarehouse.com.contract.R.string.end_time_card;
import static contract.wwwarehouse.com.contract.R.string.send_time_card;
import static contract.wwwarehouse.com.contract.R.string.start_time_card;

/**
 * 发布资源
 * Created by ShineF on 2017/10/17 0017.
 */
@Route(path = "/contract/ReleaseSupplyCardFragment")

public class ReleaseSupplyCardFragment extends BaseFragment implements View.OnClickListener, ElasticScrollView.OnPullListener, EasyPopupWindow.ChildClickListener {

    private ElasticScrollView mCustomScrollView;
    private StateLayout mSlState;
    private RelativeLayout mRlEffectTime;
    private TextView mTvEffectStartTime;
    private TextView mTvEffectEndTime;
    private TextView mTvEffectTime;
    private LinearLayout mllReleaseTimeContent;
    private RelativeLayout mRlReleaseObject;
    private TextView mTvReleaseObject;
    private RelativeLayout mRlReleaseGoods;
    private TextView mTvReleaseGoods;
    private RelativeLayout mRlPayItem;
    private TextView mTvPayTimeTitle;
    private TextView mTvPayCycle;
    private TextView mTvPayType;
    private LinearLayout mllPayItemContent;
    private RelativeLayout mRlDeliveryItem;
    private TextView mTvDeliveryItem;
    private TextView mRlOrderTime;
    private TextView mRlDeliveryTitle;
    private TextView mRlDeliveryTime;
    private LinearLayout mllDeliveryItemContent;
    private RelativeLayout mRlObligationItem;
    private TextView mTvObligationTime;
    private TextView mTvObligationType;
    private TextView mTvObligationTitle;
    private LinearLayout mllObligationItemContent;
    private boolean isShow = false;
    private boolean isBack = false;

    private static final int CONTINUE_SUPPLY_CARD = 2;
    private static final int SUBMIT_SUPPLY_CARD = 3;
    private static final int CANCEL_SUPPLY_CARD = 4;
    private static final int SUPPLY_CARD_DIALOG = 5;
    private static final int END_RELEASE_CARD_DIALOG = 6;
    private static final int EDIT_AND_INFO_CARD = 7;
    private static final int CHECK_PERMISSION = 8;

    private String pbUkid = null;
    private String mReleaseObjectName = "";
    private ArrayList<String> publishData;
    private boolean isCreatPay = true;
    private boolean isCreatDelivery = true;
    private boolean isCreatObligation = true;
    private String buId;
    private String obligationTempUkid;
    private EasyPopupWindow mEasyPopupWindow;
    private String validType;
    private String start;
    private String end;
    //    private int mSelectSize = -1;
    private int count;
    private String cardContractUkid;
    private String cardBusinessId;
    private String mCardType;
    private Long mObligationOrderUkid;
    private ReleaseSupplyGoodsListBean.ListBean mListBean;
    private int mGoodsCount = -1;
    private List<SettingRuleBean.DataBean.ListBean> pbRsItemTempBean;
    private List<ResourceItemBean.DataBean.ListBean> select;
    private String mCardUnitUkid;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_release_supply_card, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mCustomScrollView = $(R.id.esv_srcoll_view);
        mSlState = $(R.id.sl_state);
        mRlEffectTime = $(R.id.rl_effect_time);
        mTvEffectTime = $(R.id.tv_effect_time);
        mTvEffectStartTime = $(R.id.tv_start_time);
        mTvEffectEndTime = $(R.id.tv_end_time);
        mllReleaseTimeContent = $(R.id.ll_release_supply_time_content);
        mRlReleaseObject = $(R.id.rl_release_object);
        mTvReleaseObject = $(R.id.tv_releast_object);
        mRlReleaseGoods = $(R.id.rl_goods);
        mRlPayItem = $(R.id.rl_pay_item);
        mRlDeliveryItem = $(R.id.rl_delivery_item);
        mRlObligationItem = $(R.id.rl_obligation_item);
        mTvReleaseGoods = $(R.id.tv_release_goods);
        mllPayItemContent = $(R.id.ll_release_pay_item_content);
        mTvPayCycle = $(R.id.tv_pay_cycle);
        mTvPayType = $(R.id.tv_pay_type);
        mTvPayTimeTitle = $(R.id.tv_release_pay_item);
        mTvDeliveryItem = $(R.id.tv_releast_delivery_item);
        mRlOrderTime = $(R.id.tv_order_time);
        mRlDeliveryTitle = $(R.id.tv_delivery_time_title);
        mRlDeliveryTime = $(R.id.tv_delivery_time);
        mllDeliveryItemContent = $(R.id.ll_delivery_content);
        mTvObligationTime = $(R.id.tv_obligation_time);
        mTvObligationType = $(R.id.tv_obligation_type);
        mllObligationItemContent = $(R.id.ll_obligation_content);
        mTvObligationTitle = $(R.id.tv_releast_obligation_item);
        mRlEffectTime.setSelected(true);
        mSlState.showProgressView(true);
        mCustomScrollView.setVisibility(View.GONE);
        ContractCommon.getInstance().getPublishObjData().clear();
    }

    @Override
    public void setTitle() {
        if (mCardType == null) {
            return;
        }
        if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_FUNCTION_RELEASE)
                || mCardType.equals(ContractConstant.RELEASE_SUPPLY_TASK_RELEASE)) {
            mActivity.setTitle(R.string.release_goods_title);
        } else if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT)
                || mCardType.equals(ContractConstant.RELEASE_SUPPLY_INFO)) {
            mActivity.setTitle(getString(R.string.info_release_title));
        }
    }

    @Override
    public void requestDatas() {
        mCustomScrollView.setOnPullListener(this);
        EventBus.getDefault().register(this);
        mRlEffectTime.setOnClickListener(this);
        mRlReleaseObject.setOnClickListener(this);
        mRlReleaseGoods.setOnClickListener(this);
        mRlPayItem.setOnClickListener(this);
        mRlDeliveryItem.setOnClickListener(this);
        mRlObligationItem.setOnClickListener(this);
        Bundle bundle = getArguments();
        if (null == bundle) {
            return;
        }
        mCardType = bundle.getString("type");
        if (TextUtils.isEmpty(mCardType)) {
            return;
        }
        isBack = bundle.getBoolean("isBack");
        if (ContractConstant.RELEASE_SUPPLY_TASK_RELEASE.equals(mCardType)) { //任务卡发布
            CardDeskTaskResponseBean.TaskBean continueBean = (CardDeskTaskResponseBean.TaskBean) bundle.getSerializable(Constant.KEY_CARD_DESK_TASK_DETAILS);
            if (null == continueBean) {
                return;
            }
            if (peekFragment() instanceof ReleaseSupplyCardFragment) {
                mActivity.setTitle(R.string.release_goods_title);
            }
            buId = continueBean.getBelongBusiness();
            ((BaseCardDeskActivity) mActivity).setTitleBt1Text(getString(R.string.cancel_release_btn));
            ((BaseCardDeskActivity) mActivity).setTitleBt2Text(getString(R.string.submit_release_btn));
            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(false);
            ((BaseCardDeskActivity) mActivity).setTitleBt2Enable(false);
            mRlReleaseObject.setEnabled(false);
            mRlReleaseGoods.setEnabled(false);
            mRlPayItem.setEnabled(false);
            mRlDeliveryItem.setEnabled(false);
            mRlObligationItem.setEnabled(false);
            Map<String, Object> map = new HashMap<>();
            map.put("operationId", continueBean.getCardUkid());
            loadData(ContractConstant.LOAD_CONTINUE_CARD_SUPPLY_RELEASE, map, CONTINUE_SUPPLY_CARD);
        } else if (ContractConstant.RELEASE_SUPPLY_FUNCTION_RELEASE.equals(mCardType)) { //功能卡发布
            CardDeskFunctionResponseBean.TaskBean taskBean =
                    (CardDeskFunctionResponseBean.TaskBean) bundle.getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS);
            if (taskBean == null) {
                return;
            }
            if (peekFragment() instanceof ReleaseSupplyCardFragment) {
                mActivity.setTitle(R.string.release_goods_title);
            }
            buId = taskBean.getBusinessId();
            ((BaseCardDeskActivity) mActivity).setTitleBt1Text("取消发布");
            ((BaseCardDeskActivity) mActivity).setTitleBt2Text("提交发布");
            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(false);
            ((BaseCardDeskActivity) mActivity).setTitleBt2Enable(false);
            mSlState.showContentView();
            mCustomScrollView.setVisibility(View.VISIBLE);
            mRlReleaseObject.setEnabled(false);
            mRlReleaseGoods.setEnabled(false);
            mRlPayItem.setEnabled(false);
            mRlDeliveryItem.setEnabled(false);
            mRlObligationItem.setEnabled(false);

            mllReleaseTimeContent.setVisibility(View.GONE);
            mllPayItemContent.setVisibility(View.GONE);
            mllDeliveryItemContent.setVisibility(View.GONE);
            mllObligationItemContent.setVisibility(View.GONE);
        } else if (ContractConstant.RELEASE_SUPPLY_INFO.equals(mCardType)
                || ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT.equals(mCardType)) { //信息卡和功能卡修改
            if (peekFragment() instanceof ReleaseSupplyCardFragment) {
                mActivity.setTitle(getString(R.string.info_release_title));
            }
            mListBean = bundle.getParcelable("data");
            if (mListBean == null) {
                return;
            }
            cardContractUkid = mListBean.getContractUkid();
            cardBusinessId = mListBean.getSupplierBusinessId();
            mReleaseObjectName = mListBean.getDemandSignName();
            mCardUnitUkid = bundle.getString("cardUnitUkid");
            //判断是否有修改的权限
            if (ContractConstant.RELEASE_SUPPLY_INFO.equals(mCardType)) {
                ((BaseCardDeskActivity) mActivity).setTitleBt1Text(getString(R.string.edit_release_supply));
                Map<String, Object> map = new HashMap<>();
                map.put("businessUnitId", cardBusinessId);
                map.put("cardUnitUkid", mCardUnitUkid);
                loadData(ContractConstant.CHECK_PERMISSION, map, CHECK_PERMISSION);
            }
            if (ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT.equals(mCardType)) {
                ((BaseCardDeskActivity) mActivity).setTitleBt1Text(getString(R.string.edit_success_info));
                ((BaseCardDeskActivity) mActivity).setTitleBt2Text(getString(R.string.end_release_btn));
                ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(true);
                ((BaseCardDeskActivity) mActivity).setTitleBt2Enable(true);
            }

            // 修改发布和信息卡片发布是一个借口, 只不过状态不一样
            Map<String, Object> map = new HashMap<>();
            map.put("contractUkid", cardContractUkid);
            loadData(ContractConstant.LOAD_EDIT_CARD_SUPPLY_RELEASE, map, EDIT_AND_INFO_CARD);

            mRlEffectTime.setEnabled(false);
            mRlReleaseObject.setEnabled(false);
            mRlReleaseGoods.setEnabled(true);
            mRlPayItem.setEnabled(true);
            mRlDeliveryItem.setEnabled(true);
            mRlObligationItem.setEnabled(true);

            mRlEffectTime.setSelected(false);
            mRlReleaseObject.setSelected(false);
            mRlReleaseGoods.setSelected(true);
            mRlPayItem.setSelected(true);
            mRlDeliveryItem.setSelected(true);
            mRlObligationItem.setSelected(true);
            mSlState.showProgressView(true);

        }
    }

    @Override
    public void onClick(View view) {
        ((BaseCardDeskActivity) mActivity).hideTitleBt();
        if (R.id.rl_effect_time == view.getId()) {
            EffectTimeFragment effectTimeFragment = new EffectTimeFragment();
            Bundle bundle = new Bundle();
            bundle.putString("pbUkid", pbUkid);
            bundle.putString("buId", buId);
            bundle.putString("validType", validType);
            bundle.putString("start", start);
            bundle.putString("end", end);
//            bundle.putString("buName", buName);
            effectTimeFragment.setArguments(bundle);
            pushFragment(effectTimeFragment);
        } else if (R.id.rl_release_object == view.getId()) {
            mEasyPopupWindow = PopUpUtils.showPopUpBottom(R.layout.release_object, getContext()
                    , getActivity().findViewById(android.R.id.content), true, ReleaseSupplyCardFragment.this);
        } else if (R.id.rl_goods == view.getId()) {
            switch (mCardType) {
                case ContractConstant.RELEASE_SUPPLY_TASK_RELEASE:
                case ContractConstant.RELEASE_SUPPLY_FUNCTION_RELEASE: {
                    PublishGoodSFragment releaseGoodsFragment = new PublishGoodSFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("pbUkid", pbUkid);
                    bundle.putString("buId", buId);
                    bundle.putSerializable("selectList", (Serializable) pbRsItemTempBean);
                    bundle.putSerializable("select", (Serializable) select);
                    bundle.putInt("count", count);
                    bundle.putString("type", mCardType);
                    releaseGoodsFragment.setArguments(bundle);
                    pushFragment(releaseGoodsFragment);
                    break;
                }
                case ContractConstant.RELEASE_SUPPLY_INFO:
                    InfoCardOrderDetailViewPagerFragment pagerFragment = new InfoCardOrderDetailViewPagerFragment();
                    Bundle infoShopBundle = new Bundle();
                    infoShopBundle.putString("type", mCardType);
                    infoShopBundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
                    pagerFragment.setArguments(infoShopBundle);
                    pushFragment(pagerFragment);
                    break;
                case ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT: {
                    IssuedGoodsViewPagerFragment issuedGoodsFragment = new IssuedGoodsViewPagerFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("type", mCardType);
                    bundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
                    bundle.putString(ContractConstant.KEY_SUPPLIER_BUSINESSID, cardBusinessId);
//                    bundle.putString(ContractConstant.KEY_SUPPLIER_BUSINESSID, "10001495");
                    issuedGoodsFragment.setArguments(bundle);
                    pushFragment(issuedGoodsFragment);
                    break;
                }
            }
        } else if (R.id.rl_pay_item == view.getId()) {
            if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_INFO)) {
                InfoCardPayItemFragment infoPayFragment = new InfoCardPayItemFragment();
                Bundle infoPayBundle = new Bundle();
                infoPayBundle.putString("type", mCardType);
                infoPayBundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
                infoPayFragment.setArguments(infoPayBundle);
                pushFragment(infoPayFragment);
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putBoolean(ContractConstant.KEY_BOOLEAN_PAY_ITEM_CREATE, isCreatPay);
            bundle.putString(ContractConstant.KEY_PAY_ITEM_PBUKID, pbUkid);
            bundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
            bundle.putString("type", mCardType);
            ReleasePayItemFragment payItemFragment = new ReleasePayItemFragment();
            payItemFragment.setArguments(bundle);
            pushFragment(payItemFragment);
        } else if (R.id.rl_delivery_item == view.getId()) {
            if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_INFO)) {
                InfoCardDeliverItemFragment infoDeliveryFragment = new InfoCardDeliverItemFragment();
                Bundle infoDeliveryBundle = new Bundle();
                infoDeliveryBundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
                infoDeliveryBundle.putString("type", mCardType);
                infoDeliveryFragment.setArguments(infoDeliveryBundle);
                pushFragment(infoDeliveryFragment);
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putBoolean(ContractConstant.KEY_BOOLEAN_DELIVERY_ITEM_IS_CREATE, isCreatDelivery);
            bundle.putString(ContractConstant.KEY_DELIVERY_ITEM_PBUKID, pbUkid);
            bundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
            bundle.putString("type", mCardType);
            ReleaseDeliveryItemFragment releaseDeliveryItemFragment = new ReleaseDeliveryItemFragment();
            releaseDeliveryItemFragment.setArguments(bundle);
            pushFragment(releaseDeliveryItemFragment);
        } else if (R.id.rl_obligation_item == view.getId()) {
            if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_INFO)) {
                InfoCardCompulsoryFragment infoObligationFragment = new InfoCardCompulsoryFragment();
                Bundle infoObligationBundle = new Bundle();
                infoObligationBundle.putString("type", mCardType);
                infoObligationBundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
                infoObligationFragment.setArguments(infoObligationBundle);
                pushFragment(infoObligationFragment);
                return;
            }
            ReleaseObligationItemFragment obligationFragment = new ReleaseObligationItemFragment();
            Bundle obligationBundle = new Bundle();
            obligationBundle.putString("type", mCardType);
            obligationBundle.putString(ContractConstant.KEY_DELIVERY_ITEM_PBUKID, pbUkid);
            obligationBundle.putString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID, cardContractUkid);
            obligationBundle.putString(ContractConstant.KEY_DELIVERY_ITEM_OBLIGATION_TEMP_UKID, obligationTempUkid);
            obligationBundle.putBoolean(ContractConstant.KEY_BOOLEAN_DELIVERY_ITEM_IS_CREATE, isCreatObligation);
            if (null != mObligationOrderUkid) {
                obligationBundle.putLong(ContractConstant.KEY_BOOLEAN_OBLIGATION_ITEM_ORDER_ID, mObligationOrderUkid);
            }
            obligationFragment.setArguments(obligationBundle);
            pushFragment(obligationFragment);
        } else if (view.getId() == R.id.btn_to_all) {
            pbObjectType = "0";
            requestObject();
        } else if (view.getId() == R.id.btn_to_point) {
            pbObjectType = "1";
            requestObject();
        } else if (view.getId() == R.id.btn_cancel) {
            if (mEasyPopupWindow != null && mEasyPopupWindow.isShowing()) {
                mEasyPopupWindow.dismiss();
            }
        }

    }

    //    类型【0、选择所有 1、选择单个】
    private String pbObjectType;

    private void requestObject() {
        Map<String, Object> map = new HashMap<>();
        map.put("buId", buId); //   业务单位ID(必填)
        map.put("orderSort", "DESC"); //  排序(DESC,ASC)
        map.put("orderType", "related_time"); //  按建立时间 related_time空为按客户名称排序
        map.put("page", "1"); //  页数(分页，必填)
        map.put("relationType", "CUSTOMER"); //  CUSTOMER客户 SUPPLIER供应商
        map.put("searchText", ""); // 搜索文字(选填，空则搜全部，模糊搜索业务单位名称)
        map.put("size", "7"); // 每页数量(分页，必填)
        loadData(ContractConstant.RELATIONBUSINESSUNITLIST, map, 0);
    }

    @SuppressWarnings("unchecked")
    public void onEventMainThread(Object event) {
        if (event instanceof EffectTimeEvent) {
            //设置生效时间
            // 生效类型【1、发布后生效 2、定时生效】
            pbUkid = ((EffectTimeEvent) event).getMsg();
            validType = ((EffectTimeEvent) event).getValidType();
            if ("1".equals(validType)) {
                end = ((EffectTimeEvent) event).getEnd();
                mTvEffectTime.setText(getString(R.string.release_effect_time_end_time));
                mTvEffectStartTime.setText(StringUtils.getResourceStr(mActivity, start_time_card, getString(R.string.release_effect_time_)));
                mTvEffectEndTime.setText(StringUtils.getResourceStr(mActivity, end_time_card, ((EffectTimeEvent) event).getEnd()));
            } else if ("2".equals(validType)) {
                mTvEffectTime.setText(getString(R.string.effect_time_card));
                start = ((EffectTimeEvent) event).getStart();
                end = ((EffectTimeEvent) event).getEnd();
                mTvEffectStartTime.setText(StringUtils.getResourceStr(mActivity, start_time_card, ((EffectTimeEvent) event).getStart()));
                mTvEffectEndTime.setText(StringUtils.getResourceStr(mActivity, end_time_card, ((EffectTimeEvent) event).getEnd()));
            }
            mllReleaseTimeContent.setVisibility(View.VISIBLE);
            mRlReleaseObject.setEnabled(true);
            mRlReleaseObject.setSelected(true);
            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(true);
        } else if (event instanceof PublishEvent) {
            //发布对象
            publishData = ((PublishEvent) event).getData();
            mRlReleaseGoods.setEnabled(true);
            mRlReleaseGoods.setSelected(true);
//            if (mSelectSize == publishData.size()) {
//                mTvReleaseObject.setText(getString(R.string.release_all));
//            } else {
            mTvReleaseObject.setText(StringUtils.getResourceStr(mActivity, R.string.release_num_card, publishData.size()));
//            }
        } else if (event instanceof PublishingRulesEvent) {
            //发布商品
            pbRsItemTempBean = ((PublishingRulesEvent) event).getDataBean();
            select = ((PublishingRulesEvent) event).getSelect();
            if (pbRsItemTempBean == null && mGoodsCount == -1) {
                mRlReleaseGoods.setSelected(true);
                mTvReleaseGoods.setText("商品");
                mRlPayItem.setSelected(false);
                mRlPayItem.setEnabled(false);
                mRlDeliveryItem.setSelected(false);
                mRlDeliveryItem.setEnabled(false);
                mRlObligationItem.setSelected(false);
                mRlObligationItem.setEnabled(false);
            } else {
                mRlPayItem.setEnabled(true);
                mRlReleaseGoods.setSelected(true);
                if (null != pbRsItemTempBean) {
                    mTvReleaseGoods.setText(StringUtils.getResourceStr(mActivity, R.string.sku_num_card_sum, pbRsItemTempBean.size()));
                } else {
                    mTvReleaseGoods.setText(StringUtils.getResourceStr(mActivity, R.string.sku_num_card_sum, mGoodsCount));
                }
                mRlPayItem.setSelected(true);
                mRlPayItem.setEnabled(true);
                mRlDeliveryItem.setSelected(true);
                mRlDeliveryItem.setEnabled(true);
                mRlObligationItem.setSelected(true);
                mRlObligationItem.setEnabled(true);
            }
        } else if (event instanceof PayItemEvent) {
            //设置支付项
            String payTime = ((PayItemEvent) event).getPayTime();
            String payWay = ((PayItemEvent) event).getPayWay();
            mRlDeliveryItem.setEnabled(true);
            mRlPayItem.setSelected(true);
            mTvPayTimeTitle.setText(R.string.payment_item_title);
            mTvPayCycle.setText(payTime);
            mTvPayType.setText(payWay);
            mllPayItemContent.setVisibility(View.VISIBLE);
            this.isCreatPay = false;
            ((BaseCardDeskActivity) mActivity).setTitleBt2Enable(true);
        } else if (event instanceof DeliveryItemEvent) {
            //交付项
            String orderTime = ((DeliveryItemEvent) event).getComitTime();
            String deliveryTime = ((DeliveryItemEvent) event).getDeviTime();
            mTvDeliveryItem.setText(getString(send_time_card));
            mRlOrderTime.setText(orderTime);
            mRlDeliveryTitle.setText(getString(delivery_time_title_card));
            mRlDeliveryTime.setText(deliveryTime);
            mllDeliveryItemContent.setVisibility(View.VISIBLE);
            this.isCreatDelivery = false;
        } else if (event instanceof ObligationItemEvent) {
            //义务项
            mTvObligationTitle.setText(getString(R.string.arrival_time_title));
            this.obligationTempUkid = ((ObligationItemEvent) event).getObligationTempUkid();
            String data = ((ObligationItemEvent) event).getData();
            boolean isDiscount = ((ObligationItemEvent) event).isDiscount();
            String discount = ((ObligationItemEvent) event).getDiscount();
            mTvObligationTime.setText(data);
            if (isDiscount) {
                mTvObligationType.setText(StringUtils.getResourceStr(mActivity, R.string.discount_num_card, discount));
            } else {
                mTvObligationType.setText(getString(R.string.rongren));
            }
            mllObligationItemContent.setVisibility(View.VISIBLE);
            this.isCreatObligation = false;
        } else if (event instanceof CountEvent) {
            //保存选择发布商品的数量,别问我问什么放这里，我特么也很蛋疼
            count = ((CountEvent) event).getCount();
            if (count >= 0) {
                mGoodsCount = count;
                mRlPayItem.setEnabled(true);
                mRlReleaseGoods.setSelected(true);
                mTvReleaseGoods.setText(StringUtils.getResourceStr(mActivity, R.string.sku_num_card_sum, count));
                mRlPayItem.setSelected(true);
                mRlPayItem.setEnabled(true);
                mRlDeliveryItem.setSelected(true);
                mRlDeliveryItem.setEnabled(true);
                mRlObligationItem.setSelected(true);
                mRlObligationItem.setEnabled(true);
            }
        } else if (event instanceof RefreshPublishGoodsEvent &&
                (mCardType.equals(ContractConstant.RELEASE_SUPPLY_INFO) || mCardType.equals(ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT))) {
            if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT)) {
                ((BaseCardDeskActivity) mActivity).setTitleBt1Text(getString(R.string.edit_success_info));
                ((BaseCardDeskActivity) mActivity).setTitleBt2Text(getString(R.string.end_release_btn));
                ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(true);
                ((BaseCardDeskActivity) mActivity).setTitleBt2Enable(true);
            }
            showProgressDialog();
            Map<String, Object> map = new HashMap<>();
            map.put("contractUkid", cardContractUkid);
            loadData(ContractConstant.LOAD_EDIT_CARD_SUPPLY_RELEASE, map, EDIT_AND_INFO_CARD);
        } else if (event instanceof NotifyDeleteEvent) {
            if (pbRsItemTempBean != null && pbRsItemTempBean.size() != 0) {
                for (int i = 0; i < pbRsItemTempBean.size(); i++) {
                    if (pbRsItemTempBean.get(i).getDefinedUkid().equals(((NotifyDeleteEvent) event).getMsg())) {
                        pbRsItemTempBean.remove(i);
                        PublishingRulesEvent publishingRulesEvent = new PublishingRulesEvent(pbRsItemTempBean);
                        EventBus.getDefault().post(publishingRulesEvent);
                        break;
                    }
                }

            }
        }
    }


    public void onEventMainThread(BackListenerEvent event) {
        if (peekFragment() instanceof ReleaseSupplyCardFragment && event.getMsg().equals("ReleaseSupplyCardFragment")) {
            LogUtils.showErrLog("boolean -----> Event Back " + isBack);
            if (isBack) {
                popFragment();
                ReleaseSupplyCardFragment cardFragment = new ReleaseSupplyCardFragment();
                Bundle bundle = new Bundle();
                bundle.putString("type", ContractConstant.RELEASE_SUPPLY_INFO);
                bundle.putParcelable("data", mListBean);
                cardFragment.setArguments(bundle);
                pushFragment(cardFragment);
            } else {
                EventBus.getDefault().post(new RefreshEvent("refresh"));
                popFragment();
            }
        }
    }

    /**
     * 提交发布
     */
    @Override
    public void titleBt2Click() {
        super.titleBt2Click();
        if (peekFragment() instanceof ReleaseSupplyCardFragment) {
            if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_FUNCTION_RELEASE)
                    || mCardType.equals(ContractConstant.RELEASE_SUPPLY_TASK_RELEASE)) {
                if (mGoodsCount <= 0) {
                    ToastUtils.showToast(getString(R.string.release_goods_null));
                    return;
                }
                Map<String, Object> map = new HashMap<>();
                map.put("pbUkid", pbUkid);
                loadData(ContractConstant.SUPPLY_CARD_DIALOG, map, SUPPLY_CARD_DIALOG);
            } else if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT)) {
                DialogTools.getInstance().showCustomDialogPrompt(mActivity, getString(R.string.end_release_supply_title), getString(R.string.end_release_supply_content)
                        , true, new DialogTools.ConfirmListener() {
                            @Override
                            public void setConfirmListener(Dialog dialog, View view, String s) {
                                Map<String, Object> map = new HashMap<>();
                                map.put("contractUkid", cardContractUkid);
                                loadData(ContractConstant.END_RELEASE_SUPPLY_LIST, map, END_RELEASE_CARD_DIALOG);
                                dialog.dismiss();
                            }
                        }, getString(R.string.end_release_supply_confirm), getString(R.string.release_supply_card_cancel));
            }
        }
    }

    /**
     * 取消发布
     */
    @Override
    public void titleBt1Click() {
        super.titleBt1Click();
        if (peekFragment() instanceof ReleaseSupplyCardFragment) {
            switch (mCardType) {
                case ContractConstant.RELEASE_SUPPLY_FUNCTION_RELEASE:
                case ContractConstant.RELEASE_SUPPLY_TASK_RELEASE:
                    DialogTools.getInstance().showCustomDialogPrompt(mActivity, getString(R.string.cancel_dialog_dialog), getString(R.string.cancel_dialog_content)
                            , true, new DialogTools.ConfirmListener() {
                                @Override
                                public void setConfirmListener(Dialog dialog, View view, String s) {
                                    Map<String, Object> map = new HashMap<>();
                                    map.put("pbUkid", pbUkid);
                                    loadData(ContractConstant.CANCEL_CARD_SUPPLY_RELEASE, map, CANCEL_SUPPLY_CARD);
                                    dialog.dismiss();
                                }
                            }, getString(R.string.cancel_2), getString(R.string.no_cancel));
                    break;
                case ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT:
                    if (isBack) {
                        popFragment();
                        ReleaseSupplyCardFragment cardFragment = new ReleaseSupplyCardFragment();
                        Bundle bundle = new Bundle();
                        bundle.putString("type", ContractConstant.RELEASE_SUPPLY_INFO);
                        bundle.putParcelable("data", mListBean);
                        bundle.putString("cardUnitUkid", mCardUnitUkid);
                        cardFragment.setArguments(bundle);
                        pushFragment(cardFragment);
                    } else {
                        popFragment();
                        EventBus.getDefault().post(new RefreshEvent("refresh"));
                    }
                    break;
                case ContractConstant.RELEASE_SUPPLY_INFO:
                    popFragment();
                    ReleaseSupplyCardFragment fragment = new ReleaseSupplyCardFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("type", ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT);
                    bundle.putParcelable("data", mListBean);
                    bundle.putBoolean("isBack", true);
                    bundle.putString("cardUnitUkid", mCardUnitUkid);
                    fragment.setArguments(bundle);
                    pushFragment(fragment);
                    ((BaseCardDeskActivity) mActivity).hideTitleBt();
                    LogUtils.showErrLog("boolean -----> btn click " + isBack);
                    break;
            }
        }
    }


    @Override
    public void onDownPull() {
        if (isShow) {
            ((BaseCardDeskActivity) mActivity).hideTitleBt();
        } else {
            switch (mCardType) {
                case ContractConstant.RELEASE_SUPPLY_FUNCTION_RELEASE:
                case ContractConstant.RELEASE_SUPPLY_TASK_RELEASE:  //发布商品和继续发布商品
                    ((BaseCardDeskActivity) mActivity).showTitleBt2();
                    break;
                case ContractConstant.RELEASE_SUPPLY_INFO:  //信息卡发布商品
                    ((BaseCardDeskActivity) mActivity).showTitleBt1();
                    break;
                case ContractConstant.RELEASE_SUPPLY_FUNCTION_EDIT:  //功能卡修改发布商品
                    ((BaseCardDeskActivity) mActivity).showTitleBt2();
                    break;
            }
        }
        isShow = !isShow;
    }

    @Override
    public void onUpPull() {

    }

    /**
     * 数据请求
     *
     * @param url  请求URL
     * @param map  请求参数
     * @param what what
     */
    public void loadData(String url, Map map, int what) {
        NoHttpUtils.httpPost(url, map, new NoHttpUtils.OnResponseListener() {
            @Override
            public void onSucceed(CommonClass commonClass, int what) {
                if (CONTINUE_SUPPLY_CARD == what) { //继续发布
                    if ("0".equals(commonClass.getCode())) {
                        ContinueReleaseCardBean bean = parseObject(commonClass.getData().toString(), ContinueReleaseCardBean.class);
                        if (null != bean) {
                            setContinueBean(bean);
                        }
                    } else {
                        ToastUtils.showToast(commonClass.getMsg());
                    }
                } else if (SUBMIT_SUPPLY_CARD == what) { //提交发布
                    if ("0".equals(commonClass.getCode())) {
                        EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
                        ToastUtils.showToast(getString(R.string.submit_release_success));
                    } else {
                        ToastUtils.showToast(commonClass.getMsg());
                    }
                } else if (CANCEL_SUPPLY_CARD == what) { //取消发布
                    if ("0".equals(commonClass.getCode())) {
                        EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
                        ToastUtils.showToast(getString(R.string.cancel_release_success));
                    } else {
                        ToastUtils.showToast(commonClass.getMsg());
                    }
                } else if (SUPPLY_CARD_DIALOG == what) { //请求提交发布Dialog信息
                    if ("0".equals(commonClass.getCode())) {
                        SupplyDialogBean bean = parseObject(commonClass.getData().toString(), SupplyDialogBean.class);
                        DialogTools.getInstance().showCustomDialogPrompt(mActivity, getString(R.string.confirm_dialog_dialog_title)
                                , StringUtils.getResourceStr(mActivity, R.string.confirm_dialog_dialog_content, bean.getResourceNum(), bean.getContractNum())
                                , true, new DialogTools.ConfirmListener() {
                                    @Override
                                    public void setConfirmListener(Dialog dialog, View view, String s) {
                                        Map<String, Object> map = new HashMap<>();
                                        map.put("pbUkid", pbUkid);
                                        loadData(ContractConstant.SUBMIT_CARD_SUPPLY_RELEASE, map, SUBMIT_SUPPLY_CARD);
                                        dialog.dismiss();
                                    }
                                }, getString(R.string.release_confirm_card), getString(R.string.no_release_confirm_card));
                    } else {
                        ToastUtils.showToast(commonClass.getMsg());
                    }
                } else if (END_RELEASE_CARD_DIALOG == what) {
                    if ("0".equals(commonClass.getCode())) {
//                        EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
                        popFragment();
                        if (isBack) {
                            ReleaseSupplyCardFragment fragment = new ReleaseSupplyCardFragment();
                            Bundle bundle = new Bundle();
                            bundle.putString("type", ContractConstant.RELEASE_SUPPLY_INFO);
                            mListBean.setContractStatus(40);
                            bundle.putParcelable("data", mListBean);
                            bundle.putBoolean("isBack", false);
                            bundle.putString("cardUnitUkid", mCardUnitUkid);
                            fragment.setArguments(bundle);
                            pushFragment(fragment);
                        }
                        EventBus.getDefault().post(new RefreshEvent("refresh"));
                        ((BaseCardDeskActivity) mActivity).hideTitleBt();
                        ToastUtils.showToast(getString(R.string.end_release_success));
                    } else {
                        ToastUtils.showToast(commonClass.getMsg());
                    }
                } else if (0 == what) {
                    if (TextUtils.equals("0", commonClass.getCode())) {
                        if (mEasyPopupWindow != null && mEasyPopupWindow.isShowing()) {
                            mEasyPopupWindow.dismiss();
                        }
                        ReleaseObjectBean releaseObjectBean = parseObject(commonClass.getData().toString(), ReleaseObjectBean.class);
//                        if (!TextUtils.isEmpty(releaseObjectBean.getTotal())) {
//                            mSelectSize = Integer.parseInt(releaseObjectBean.getTotal());
//                        }
                        if (releaseObjectBean.getBusinessList().size() != 0) {
                            if ("0".equals(pbObjectType)) {
                                Map<String, Object> map = new HashMap<>();
                                map.put("pbUkid", pbUkid);
                                map.put("pbObjectType", pbObjectType);
                                loadData(ContractConstant.SAVEPUBLISHOBJECT, map, 100);
                            } else if ("1".equals(pbObjectType)) {
                                ReleaseObjectFragment releaseObjectFragment = new ReleaseObjectFragment();
                                Bundle bundle = new Bundle();
                                bundle.putString("total", releaseObjectBean.getTotal());
                                bundle.putString("buId", buId);         //   业务单位ID(必填)
                                bundle.putString("pbUkid", pbUkid);
                                bundle.putString("orderSort", "DESC");     //  排序(DESC,ASC)
                                bundle.putString("orderType", "related_time");      //  按建立时间 related_time空为按客户名称排序
                                bundle.putString("relationType", "CUSTOMER");     //  CUSTOMER客户 SUPPLIER供应商
                                bundle.putString("searchText", "");       // 搜索文字(选填，空则搜全部，模糊搜索业务单位名称)
                                bundle.putStringArrayList("publishData", publishData);
                                releaseObjectFragment.setArguments(bundle);
                                pushFragment(releaseObjectFragment);
                            }
                        } else {
                            //显示提示框
                            DialogTools.getInstance().showCustomWarning(getContext(), "无法添加", "尚未添加任何关系人!", "好的", true, new DialogTools.ConfirmListener() {
                                @Override
                                public void setConfirmListener(Dialog dialog, View view, String s) {
                                    dialog.dismiss();
                                }
                            });
                        }
                    } else {
                        toast(commonClass.getMsg());
                    }
                } else if (100 == what) {
                    if (TextUtils.equals("0", commonClass.getCode())) {
                        List<String> dataBean = parseArray(commonClass.getData().toString(), String.class);
                        if (dataBean != null) {
                            EventBus.getDefault().post(new PublishEvent((ArrayList<String>) dataBean));
                        }
                    }
                } else if (EDIT_AND_INFO_CARD == what) {
                    if (commonClass.getCode().equals("0")) {
                        RleaseInfoAndFunctionBean functionBean = parseObject(commonClass.getData().toString(), RleaseInfoAndFunctionBean.class);
                        if (null == functionBean) {
                            mSlState.showEmptyView(true);
                            return;
                        }
                        setInfoAndEditBean(functionBean);
                    }
                } else if (CHECK_PERMISSION == what) {
                    if (commonClass.getCode().equals("0")) {
                        List<CheckPermission> list = parseArray(commonClass.getData().toString(), CheckPermission.class);
                        if (null == list || list.size() == 0) {
                            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(false);
                            return;
                        }
                        CheckPermission checkPermission = list.get(0);
                        if (mListBean.getContractStatus() == 20 && checkPermission.getClientShow().equals("1")) {
                            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(true);
                        } else {
                            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(false);
                        }
                    }
                }
            }

            @Override
            public void onFailed(String s, int i) {

            }

            @Override
            public void onFinish(int i) {

            }
        }, what);
    }

    /**
     * 信息卡和功能卡修改设置数据
     *
     * @param functionBean 数据结构
     */
    private void setInfoAndEditBean(RleaseInfoAndFunctionBean functionBean) {
        RleaseInfoAndFunctionBean.DeliveryBean delivery = functionBean.getDelivery();
        int itemCount = functionBean.getItemCount();
        RleaseInfoAndFunctionBean.ObligationBean obligation = functionBean.getObligation();
        RleaseInfoAndFunctionBean.PaymentBean payment = functionBean.getPayment();
        RleaseInfoAndFunctionBean.PbRsHeadBean pbRsHead = functionBean.getPbRsHead();
        mTvReleaseObject.setText(mReleaseObjectName);
        if (mCardType.equals(ContractConstant.RELEASE_SUPPLY_INFO)) {
            if (null == delivery) {
                mRlDeliveryItem.setEnabled(false);
                mRlDeliveryItem.setSelected(false);
            }
            if (null == obligation) {
                mRlObligationItem.setEnabled(false);
                mRlObligationItem.setSelected(false);
            }
            if (null == payment) {
                mRlPayItem.setEnabled(false);
                mRlPayItem.setSelected(false);
            }
        }
        mTvReleaseGoods.setText(StringUtils.getResourceStr(mActivity, R.string.sku_num_card, String.valueOf(itemCount)));
        if (null != pbRsHead) {
            cardContractUkid = pbRsHead.getContractUkid();
            mllReleaseTimeContent.setVisibility(View.VISIBLE);
            //设置生效时间
            if (!TextUtils.isEmpty(pbRsHead.getValidStartTime())) {
                start = pbRsHead.getValidStartTime();
                mTvEffectTime.setText(R.string.effect_start_time_edit_time);
                mTvEffectStartTime.setText(StringUtils.getResourceStr(mActivity, start_time_card
                        , pbRsHead.getValidStartTime().substring(0, pbRsHead.getValidStartTime().length() - 3)));
            } else {
                mTvEffectTime.setText(getString(R.string.release_effect_time_end_time));
                mTvEffectStartTime.setText(StringUtils.getResourceStr(mActivity, start_time_card, getString(R.string.release_effect_time_)));
            }
            if (!TextUtils.isEmpty(pbRsHead.getValidEndTime())) {
                end = pbRsHead.getValidEndTime();
                mTvEffectEndTime.setText(StringUtils.getResourceStr(mActivity, end_time_card
                        , pbRsHead.getValidEndTime().substring(0, pbRsHead.getValidEndTime().length() - 3)));
            }
        }
        if (null != payment) {
            StringBuilder payChannel = new StringBuilder();
            if (payment.getPayMonth() != 0) {
                payChannel.append("月付、");
            }
            if (payment.getPayWeek() != 0) {
                payChannel.append("周付、");
            }
            if (payment.getPayOrderFlag() == 1) {
                payChannel.append("下单付、");
            }
            StringBuilder payType = new StringBuilder();
            if (!TextUtils.isEmpty(payment.getAccountAlipay())) {
                payType.append("支付宝、");
            }
            if (!TextUtils.isEmpty(payment.getAccountWechat())) {
                payType.append("微信付、");
            }
            if (!TextUtils.isEmpty(payment.getAccountBank())) {
                payType.append("银行卡、");
            }
            if (payment.getPayOfflineFlag() == 1) {
                payType.append("线下付、");
            }
            mTvPayTimeTitle.setText(getString(R.string.payment_item_title));
            String payChannelStr = payChannel.toString();
            mTvPayCycle.setText(payChannelStr.substring(0, payChannelStr.length() - 1));
            String payTypeStr = payType.toString();
            mTvPayType.setText(payTypeStr.substring(0, payTypeStr.length() - 1));
            mllPayItemContent.setVisibility(View.VISIBLE);
        }
        if (null != delivery) {
            mTvDeliveryItem.setText(getString(send_time_card));
            mRlOrderTime.setText(StringUtils.getResourceStr(mActivity, R.string.delivery_time_card
                    , String.valueOf(delivery.getSendEarly()), String.valueOf(delivery.getSendLast())));
            mRlDeliveryTitle.setText(getString(delivery_time_title_card));
            mRlDeliveryTime.setText(StringUtils.getResourceStr(mActivity, R.string.delivery_time_card
                    , String.valueOf(delivery.getDeliveryEarly()), String.valueOf(delivery.getDeliveryLast())));
            mllDeliveryItemContent.setVisibility(View.VISIBLE);
        }
        if (null != obligation) {
            mObligationOrderUkid = obligation.getObligationOrderUkid();
            mTvObligationTime.setText(StringUtils.getResourceStr(mActivity, R.string.obligation_time_card
                    , obligation.getDefaultValueMin(), obligation.getDefaultValueMax()));
            mTvObligationTitle.setText(getString(R.string.arrival_time_title));
            if (obligation.getRewandType() == 0) {
                mTvObligationType.setText(getString(R.string.rongren));
            } else if (obligation.getRewandType() == 1) {
                if (Integer.parseInt(obligation.getRewandValue()) > 10) {
                    double rewandValue = Double.parseDouble(obligation.getRewandValue());
                    mTvObligationType.setText(StringUtils.getResourceStr(mActivity, R.string.discount_num_card, rewandValue / 10d));
                } else {
                    mTvObligationType.setText(StringUtils.getResourceStr(mActivity, R.string.discount_num_card, obligation.getRewandValue()));
                }
            }
            mllObligationItemContent.setVisibility(View.VISIBLE);
        }
        mSlState.showContentView();
        mCustomScrollView.setVisibility(View.VISIBLE);
        dismissProgressDialog();
    }

    /**
     * 设置继续发布商品
     *
     * @param bean 数据类型R
     */
    private void setContinueBean(ContinueReleaseCardBean bean) {
        if (null != bean.getPbRsHead()) {
            ContinueReleaseCardBean.PbRsHeadBean timeBean = bean.getPbRsHead();
            pbUkid = bean.getPbRsHead().getPbUkid();
            buId = String.valueOf(bean.getPbRsHead().getSupplierBusinessId());
            mRlEffectTime.setSelected(true);
            mRlEffectTime.setEnabled(true);
            mllReleaseTimeContent.setVisibility(View.VISIBLE);
            validType = String.valueOf(timeBean.getValidType());
            //设置生效时间
            if (!TextUtils.isEmpty(timeBean.getValidStartTime())) {
                start = timeBean.getValidStartTime();
                mTvEffectTime.setText(R.string.timing_effect);
                mTvEffectStartTime.setText(StringUtils.getResourceStr(mActivity, start_time_card
                        , timeBean.getValidStartTime().substring(0, timeBean.getValidStartTime().length() - 3)));
            } else {
                mTvEffectTime.setText(getString(R.string.release_effect_time_end_time));
                mTvEffectStartTime.setText(StringUtils.getResourceStr(mActivity, start_time_card, getString(R.string.release_effect_time_)));
            }
            if (!TextUtils.isEmpty(timeBean.getValidEndTime())) {
                end = timeBean.getValidEndTime();
                mTvEffectEndTime.setText(StringUtils.getResourceStr(mActivity, end_time_card
                        , timeBean.getValidEndTime().substring(0, timeBean.getValidEndTime().length() - 3)));
            }
            ((BaseCardDeskActivity) mActivity).setTitleBt1Enable(true);
            mRlReleaseObject.setEnabled(true);
            mRlReleaseObject.setSelected(true);
            List<Integer> pbObjectSelect = timeBean.getPbObjectSelect();
            //设置发布对象
            if (pbObjectSelect != null) {
                publishData = new ArrayList<>();
                for (int i = 0; i < pbObjectSelect.size(); i++) {
                    publishData.add(pbObjectSelect.get(i) + "");
                }
                mTvReleaseObject.setText(StringUtils.getResourceStr(mActivity, R.string.release_num_card, pbObjectSelect.size()));
                mRlReleaseGoods.setEnabled(true);
                mRlReleaseGoods.setSelected(true);
            }
        }
        mGoodsCount = bean.getItemCount();
        //设置商品
        if (mGoodsCount > 0 || (mGoodsCount == 0 && null != bean.getPayment())) {
            this.count = bean.getItemCount();
            mTvReleaseGoods.setText(StringUtils.getResourceStr(mActivity, R.string.sku_num_card, bean.getItemCount()));
            mRlPayItem.setSelected(true);
            mRlPayItem.setEnabled(true);
            mRlDeliveryItem.setSelected(true);
            mRlDeliveryItem.setEnabled(true);
            mRlObligationItem.setSelected(true);
            mRlObligationItem.setEnabled(true);
        }
        //设置支付项
        if (null != bean.getPayment()) {
            isCreatPay = false;
            ContinueReleaseCardBean.PaymentBean payBean = bean.getPayment();
            mTvPayTimeTitle.setText(getString(R.string.payment_item_title));
            StringBuilder payChannel = new StringBuilder();
            if (payBean.getPayMonth() != 0) {
                payChannel.append("月付、");
            }
            if (payBean.getPayWeek() != 0) {
                payChannel.append("周付、");
            }
            if (payBean.getPayOrderFlag() == 1) {
                payChannel.append("下单付、");
            }

            StringBuilder payType = new StringBuilder();
            if (!TextUtils.isEmpty(payBean.getAccountAlipay())) {
                payType.append("支付宝、");
            }
            if (!TextUtils.isEmpty(payBean.getAccountWechat())) {
                payType.append("微信付、");
            }
            if (!TextUtils.isEmpty(payBean.getAccountBank())) {
                payType.append("银行卡、");
            }
            if (payBean.getPayOfflineFlag() == 1) {
                payType.append("线下付、");
            }
            String payChannelStr = payChannel.toString();
            mTvPayCycle.setText(payChannelStr.substring(0, payChannelStr.length() - 1));
            String payTypeStr = payType.toString();
            mTvPayType.setText(payTypeStr.substring(0, payTypeStr.length() - 1));
            mllPayItemContent.setVisibility(View.VISIBLE);
            ((BaseCardDeskActivity) mActivity).setTitleBt2Enable(true);
        }
        //设置交付项
        if (null != bean.getDelivery()) {
            isCreatDelivery = false;
            ContinueReleaseCardBean.DeliveryBean deliveryBean = bean.getDelivery();
            mTvDeliveryItem.setText(getString(send_time_card));
            mRlOrderTime.setText(StringUtils.getResourceStr(mActivity, R.string.delivery_time_card
                    , String.valueOf(deliveryBean.getSendEarly()), String.valueOf(deliveryBean.getSendLast())));
            mRlDeliveryTitle.setText(getString(delivery_time_title_card));
            mRlDeliveryTime.setText(StringUtils.getResourceStr(mActivity, R.string.delivery_time_card
                    , String.valueOf(deliveryBean.getDeliveryEarly()), String.valueOf(deliveryBean.getDeliveryLast())));
            mllDeliveryItemContent.setVisibility(View.VISIBLE);
        }
        //设置义务项
        if (null != bean.getObligation()) {
            isCreatObligation = false;
            ContinueReleaseCardBean.ObligationBean obligationBean = bean.getObligation();
            mObligationOrderUkid = obligationBean.getObligationTempUkid();
            mTvObligationTitle.setText(getString(R.string.arrival_time_title));
            mTvObligationTime.setText(StringUtils.getResourceStr(mActivity, R.string.obligation_time_card
                    , obligationBean.getDefaultValueMin(), obligationBean.getDefaultValueMax()));
            if (obligationBean.getRewandType() == 0) {
                mTvObligationType.setText(getString(R.string.rongren));
            } else if (obligationBean.getRewandType() == 1) {
                if (Integer.parseInt(obligationBean.getRewandValue()) > 10) {
                    double rewandValueTemp = Double.parseDouble(obligationBean.getRewandValue());
                    mTvObligationType.setText(StringUtils.getResourceStr(mActivity, R.string.discount_num_card, rewandValueTemp / 10d));
                } else {
                    mTvObligationType.setText(StringUtils.getResourceStr(mActivity, R.string.discount_num_card, obligationBean.getRewandValue()));
                }

            }
            mllObligationItemContent.setVisibility(View.VISIBLE);
        } else {
            isCreatObligation = true;
        }
        mSlState.showContentView();
        mCustomScrollView.setVisibility(View.VISIBLE);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ((BaseCardDeskActivity) mActivity).hideTitleBt();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void getChildView(int i, View view) {
        Button take = (Button) view.findViewById(R.id.btn_to_all);
        Button gallery = (Button) view.findViewById(R.id.btn_to_point);
        Button cancel = (Button) view.findViewById(R.id.btn_cancel);

        take.setOnClickListener(this);
        gallery.setOnClickListener(this);
        cancel.setOnClickListener(this);
    }

}